package com.zhf.douyinvideo

import android.support.v4.app.Fragment
import android.widget.TextView
import com.zhf.douyinvideo.base.BaseActivity
import com.zhf.douyinvideo.fragment.*

class MainActivity : BaseActivity() {
	
	// 直接初始化首页,订单,个人,更多的fragment
	val fragments: List<Fragment> = listOf<Fragment>(HomeFragment(), CourseFragment("Tab2"),  CourseFragment("Tab3"),  CourseFragment("Tab4"), CourseFragment("Tab5"))
	
	private var currentPosition: Int = 0
	
	override val contentLayoutId: Int
		get() = R.layout.activity_main
	
	
	override fun initBefore() {
		super.initBefore()
		
		//默认选择第一个
		changeIndex(0)
	}
	
	override fun initData() {
		super.initData()
		var tab1 :TextView= findViewById(R.id.tab1)
		var tab2 :TextView= findViewById(R.id.tab2)
		var tab3 :TextView= findViewById(R.id.tab3)
		var tab4 :TextView= findViewById(R.id.tab4)
		var tab5 :TextView= findViewById(R.id.tab5)
		
		tab1.setOnClickListener {   changeIndex(0)}
		tab2.setOnClickListener {   changeIndex(1)}
		tab3.setOnClickListener {   changeIndex(2)}
		tab4.setOnClickListener {   changeIndex(3)}
		tab5.setOnClickListener {   changeIndex(4)}
		
	}
	
	
	//设置tab点击事件的样式
	private fun changeIndex(index: Int) {
		var position = index
		currentPosition = position
		
		supportFragmentManager.beginTransaction().replace(R.id.main_content, fragments[position]).commit()
	}
	
}
